﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using HA.ModFlow.Domain.FileLayer;

namespace HA.ModFlow.Domain.DomainLayer
{
    [Serializable]
    public class PCGSolver:ICloneable
    {

        int _MXITER=1;

        /// <summary>
        /// 外部迭代的最大次数。
        /// </summary>
        public int MXITER
        {
            get { return _MXITER; }
            set { _MXITER = value; }
        }

        int _ITER1=30;


        /// <summary>
        /// 内部迭代数，当属于线性迭代时 取值范围为 10-30，
        /// </summary>
        public int ITER1
        {
            get { return _ITER1; }
            set { _ITER1 = value; }
        }


        int _CPCOND=1;
        /// <summary>
        /// 标志位，0,1 用于决定矩阵条件算法
        /// </summary>
        public int CPCOND
        {
            get { return _CPCOND; }
            set { _CPCOND = value; }
        }


        double _HCLOSE=0.01;

        /// <summary>
        /// 水头变化收敛规则，为长度单位
        /// </summary>
        public double HCLOSE
        {
            get { return _HCLOSE; }
            set { _HCLOSE = value; }
        }

        double _RCLOSE=0.01;
        /// <summary>
        /// 残差收敛规则，每次时间的立方体长度单位。
        /// 模型的长度和时间单位是一致的。在每次迭代的所有点的残差最大值
        /// 小于或等于RCLOSE和HCLOSE的准则是满足的，迭代停止。
        /// </summary>
        public double RCLOSE
        {
            get { return _RCLOSE; }
            set { _RCLOSE = value; }
        }


        double _RELAX=1.0;

        /// <summary>
        /// 松弛参数
        /// </summary>
        public double RELAX
        {
            get { return _RELAX; }
            set { _RELAX = value; }
        }

        int _NBPOL=1;
        /// <summary>
        /// 2,1 上边界的最大特征值=2，当NPCOND = 2使用
        /// </summary>
        public int NBPOL
        {
            get { return _NBPOL; }
            set { _NBPOL = value; }
        }

        int _IPRPCG=0;
        /// <summary>
        /// PCG.的输出间隔。如果等于0，则按999.
        /// </summary>
        public int IPRPCG
        {
            get { return _IPRPCG; }
            set { _IPRPCG = value; }
        }

        int _MUTPCG=0;

        /// <summary>
        /// 打印信息标志位
        /// </summary>
        public int MUTPCG
        {
            get { return _MUTPCG; }
            set { _MUTPCG = value; }
        }

        double _DAMP=1;

        /// <summary>
        /// 取值范围 0-1；1表示不damp ，damping factor阻尼系数，通常设为1，如果等于则表明无阻尼。取值在0 和1 之间
        /// </summary>
        public double DAMP
        {
            get { return _DAMP; }
            set { _DAMP = value; }
        }


        public PPreconditionedConjugateGradient ToPack()
        {

            PPreconditionedConjugateGradient pcg = new PPreconditionedConjugateGradient();
            pcg.MXITER = this.MXITER;
            pcg.ITER1 = this.ITER1;
            pcg.CPCOND = this.CPCOND;
            pcg.HCLOSE = this.HCLOSE;
            pcg.RCLOSE = this.RCLOSE;
            pcg.RELAX = this.RELAX;
            pcg.IPRPCG = this.IPRPCG;
            pcg.MUTPCG = this.MUTPCG;
            pcg.DAMP = this.DAMP;
            return pcg;
 
        }

        public object Clone()
        {
            return this.MemberwiseClone();
        }
    }
}
